using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Continous
{
    public partial class Form1 : Form
    {
        int m_ExitCode = 0;

        public Form1()
        {
            InitializeComponent();
            this.Paint += new PaintEventHandler(Form_Paint);
            timer1.Enabled = true;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                m_ExitCode = (ExecuteCommand(textBox1.Text, 3600 * 1000));
                Invalidate();         
            }
        }

        public void Form_Paint(object o, PaintEventArgs args)
        {
            using (Graphics drawingSurface = Graphics.FromHwnd(Handle))
            {
                Brush l_Brush = new SolidBrush(Color.Yellow);
                if( checkBox1.Checked )
                {
                    if( m_ExitCode == 0 )
                        l_Brush = new SolidBrush(Color.Green);
                    else
                        l_Brush = new SolidBrush(Color.Red);
                }
                drawingSurface.FillEllipse(l_Brush, 15, 5, 35, 35);
            }
            return;
        }


        public static int ExecuteCommand(string Command, int Timeout)
        {
            int ExitCode;
            ProcessStartInfo ProcessInfo;
            Process Process;

            ProcessInfo = new ProcessStartInfo("cmd.exe", "/C " + Command);
            ProcessInfo.CreateNoWindow = true; 
            ProcessInfo.UseShellExecute = false;
            Process = Process.Start(ProcessInfo);
            Process.WaitForExit(Timeout);
            ExitCode = Process.ExitCode;
            Process.Close();

            return ExitCode;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            Invalidate();
        }

    }
}